#include <iostream>
#include <vector>
#include <queue>
#include <cmath>

std::vector<std::vector<int>> kClosest(std::vector<std::vector<int>>& points, int k) {
    std::vector<std::vector<int>> result;
    
    std::priority_queue<std::pair<int, std::vector<int>>> maxHeap;

    for (const auto& point : points) {
        int distance = pow(point[0], 2) + pow(point[1], 2);
        if (maxHeap.size() < k) {
            maxHeap.push({distance, point});
        } else if (distance < maxHeap.top().first) {
            maxHeap.pop();
            maxHeap.push({distance, point});
        }
    }
  
    while (!maxHeap.empty()) {
        result.push_back(maxHeap.top().second);
        maxHeap.pop();
    }
    
    return result;
}

int main() {
    std::vector<std::vector<int>> points = {{1, 3}, {-2, 2}, {5, -1}, {0, 2}, {1, -3}};
    int k = 3;
    std::vector<std::vector<int>> closestPoints = kClosest(points, k);
    
    std::cout << "The closest " << k << " points to the origin are:\n";
    for (const auto& point : closestPoints) {
        std::cout << "(" << point[0] << ", " << point[1] << ")\n";
    }
    
    return 0;
}